博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ThinkCMF----调用指定栏目的文章列表
阅读量:7116 次
发布时间:2019-06-28

本文共 1795 字,大约阅读时间需要 5 分钟。

做项目的时候,在用ThinkCMF在首页调用指定的栏目文章,但是没有找到好的方法,就自己写了一个。

但是又不想写标签,就在公用方法里面实现了:找到common.php

操作数据库,要用到think的控制器和think的数据库类:

field(array('id','parent_id'))->select(); $category_arr = array(); $cur_category_list = array(); array_push($cur_category_list,intval($id)); foreach($category_list as $v){ $arr = array(); $arr['id'] = $v['id']; $arr['pid'] = $v['parent_id']; array_push($category_arr,$arr); } //得到当前栏目所有的子栏目ids $cur_category_ids = array_merge($cur_category_list,get_all_child($category_arr,$id)); //获取当前所有子栏目的所有文章ids $all_post_ids_arr = array(); $all_post_ids = Db::name('portal_category_post')->where('category_id','in',$cur_category_ids)->field(array('post_id'))->select(); foreach($all_post_ids as $v){ array_push($all_post_ids_arr,$v['post_id']); } // 获取当前栏目及子栏目所有的文章列表 $where = array(); $where['id'] = array('in',$all_post_ids_arr); $where['post_type'] = 1; $where['post_status'] = 1; $pagelist_arr = Db::name('portal_post')->where($where)->paginate($limit); $page = $pagelist_arr->render(); // 处理跳转链接 和 栏目的图片 $pagelist = array(); foreach($pagelist_arr as $k => $v){ $v['thumb'] = '/upload/'.json_decode($v['more'],true)['thumbnail']; $v['category_id'] = get_category_id($v['id']); array_push($pagelist,$v); } return $pagelist;}function get_category_id($id){ $categoryinfo = Db::name('portal_category_post')->where('post_id','eq',$id)->field('category_id')->find(); return $categoryinfo['category_id'];}

怎么调用?

即可

 

转载于:https://www.cnblogs.com/e0yu/p/9540967.html

你可能感兴趣的文章
Mysql主从复制配置
查看>>
rsync服务器
查看>>
使用Hexo+Github一步步搭建属于自己的博客(基础)
查看>>
数据库优化资料整理
查看>>
tomcat 原理与使用资料
查看>>
报此错错解决办法:java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
查看>>
c#.net利用RNGCryptoServiceProvider产生任意范围强随机数的办法
查看>>
旅游网站进行邮件订阅的七大步骤讲解
查看>>
shell基础
查看>>
linux 文件类型 时间戳 ls bash特性四 文件查看命令 cp move echo
查看>>
如何在XenDesktop中映射USB设备
查看>>
Java并发编程 基础知识学习总结
查看>>
Amdahl定律以及该定律在多核时代的影响
查看>>
我又发现一个直接就能安装中文小红帽的方法
查看>>
ACM弱校ACMer A HDU1045Fire Net有感
查看>>
cxgrid实现分组统计和添加Footer
查看>>
刘敏华:2013年网络营销行业展望
查看>>
Lync 客户端功能对比之IM功能
查看>>
理解MySQL——架构与概念
查看>>
vsftpd虚拟用户
查看>>